﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SharePoint.Silverlight.Clock.ControlTemplates.SharePoint.Silverlight.Clock
{
    public partial class EditorPartMain : UserControl
    {
        #region Properties
        internal string ClockTitle
        {
            get
            {
                return tbxClockTitle.Text;
            }
            set
            {
                tbxClockTitle.Text = value;
            }
        }
        internal bool ShowDigitalClock
        {
            get
            {
                return cbShowDigitalClock.Checked;
            }
            set
            {
                cbShowDigitalClock.Checked = value;
            }
        }
        internal bool ShowSecondHand
        {
            get { return cbShowSecondHand.Checked; }
            set { cbShowSecondHand.Checked = value; }
        }

        internal bool ShowMilliHand
        {
            get { return cbShowMilliHand.Checked; }
            set { cbShowMilliHand.Checked = value; }
        }
        internal bool ShowTenthsHand
        {
            get { return cbShowTenthsHand.Checked; }
            set { cbShowTenthsHand.Checked = value; }
        }

        internal string ClockTimeZoneId
        {
            get
            {
                //0 - Client time zone
                return ddlTimeZone.SelectedValue;
            }
            set
            {
                ListItem li = ddlTimeZone.Items.FindByValue(value);
                if (li != null)
                {
                    ddlTimeZone.ClearSelection();
                    li.Selected = true;
                }
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        internal void Initialize()
        {
            BindDdlTimeZones();
        }

        private void BindDdlTimeZones()
        {
            ddlTimeZone.Items.Clear();

            //Add [Not use] value
            ddlTimeZone.Items.Add(new ListItem("[Client time zone]","0"));

            foreach (var item in TimeZoneInfo.GetSystemTimeZones())
            {
                ddlTimeZone.Items.Add(new ListItem(item.DisplayName,item.Id));
            }
        }

    }
}
